home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12105 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: I need help.
  5. Date: 28 Mar 96 20:58:10 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.828046690@rscernix>
  8. References: <4j9hr7$skj@cronkite.seas.gwu.edu> <26MAR199615081545@erich.triumf.ca>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <26MAR199615081545@erich.triumf.ca> bennett@erich.triumf.ca (P.Bennett) writes:
  13.  
  14. >In article <4j9hr7$skj@cronkite.seas.gwu.edu>, celtik@gwis2.circ.gwu.edu (Tolga Celtikci) writes...
  15. >>Can anyone help me with the syntax of EOF. Is it '\o' or something else?
  16.  
  17. The "syntax" of EOF is EOF.  It works fine after including <stdio.h>.
  18.  
  19. On _some_ platforms it can be even written as a character constant: '\xff'
  20. or '\377', but:
  21.  
  22. 1. It is a very "efficient" way to obfuscate your code.  Other people
  23.    will have a very hard time figuring out what you meant.
  24.  
  25. 2. It will work only on platforms which use two's complement integers, 
  26.    define EOF as -1 and treat char as an 8-bit signed type.  OTOH, EOF
  27.    works everywhere.
  28.  
  29. >EOF is _not_ a char in the file.  It is a value returned by getchar(), fgetc()
  30. >and some other functions to indicate that they have attempted to read past
  31. >end-of-file.   It is a value that cannot be represented in a char, so getchar()
  32.                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  33. Don't be so sure.  Implementations with sizeof(char) == sizeof(int) are
  34. legal and even exist.  They're a royal pain in the ass when it comes to
  35. testing for EOF, because EOF is also a valid character value, so after
  36. reading an EOF you have to call ferror and feof to disambiguate between
  37. a genuine char value and an end-of-file condition.
  38.  
  39. Dan
  40. --
  41. Dan Pop
  42. CERN, CN Division
  43. Email: danpop@mail.cern.ch 
  44. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  45.